## This Call is using the Film2home site's API. So only use this if you got approved by MZ to use the data.
## As they are very strict about it. I will move this to their API url when they get back to me sometime.
## - Needed agruments are imdb_id (only int, but it auto removes "tt")

module Shin
  module Reviews
    class Moviezine
      
      def new
        self
      end
      
      # Currently IMDB ID is the only way
      def find(h = {})
        raise MissingArgument, "You are missing the argument 'imdb' which is required to use this source." unless h[:imdb] != ""
        
        # We got the needed things
        imdb_id_int = h[:imdb].gsub(/^tt/, "")
        response = Base.get('https://www.film2home.se/Services/MovieZine.svc/GetReview?imdbId='+imdb_id_int.to_s)
        
        # Raise error if it didn't have a correct http code.
        raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
        
        data = response.parsed_response
        {name: nil, year: nil, title: data['Title'], rating: data['Rating'].to_i, url: data['Url'], votes: nil}.to_hashugar
      end
      
      class MissingArgument  < StandardError; end
      class HTTPError        < StandardError; end
    end
  end
end